﻿namespace Shortcuts.Views
{
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Tasks;
    using Shortcuts.Common;
    using System;
    using System.Windows.Navigation;

    public partial class NavigationPage : PhoneApplicationPage
    {
        const string SettingsKey = "settings";

        public NavigationPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            switch (e.NavigationMode)
            {
                case NavigationMode.Back:
                    // exit.
                    new Microsoft.Xna.Framework.Game().Exit();
                    break;
                case NavigationMode.New:
                    if (NavigationContext.QueryString.ContainsKey(SettingsKey))
                    {
                        Settings settings = Settings.All;
                        try
                        {
                            settings = (Settings)Enum.Parse(typeof(Settings), NavigationContext.QueryString[SettingsKey], true);
                            UmengSDK.UmengAnalytics.onEvent("shortcut", settings.Named());
                        }
                        catch { }

                        if (settings != Settings.All)
                        {
                            ConnectionSettingsTask task = new ConnectionSettingsTask();
                            task.ConnectionSettingsType = settings.ToConnection();
                            task.Show();
                        }
                    }
                    break;
            }

            base.OnNavigatedTo(e);
        }
    }
}